package com.hopes.bizz.basic.job;

import cn.hutool.core.date.DateUtil;
import com.hopes.bizz.basic.park.entity.BaseParkSafeManagerEntity;
import com.hopes.bizz.basic.park.entity.BaseSafeManageMaterialEntity;
import com.hopes.bizz.basic.park.service.BaseParkSafeManagerService;
import com.hopes.bizz.basic.park.service.BaseSafeManageMaterialService;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author daijie
 * @version 1.0
 * @date 2023/10/27 13:23
 * @Description: 包保任务是否过期定时任务
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class BaseSafeExpireService {


    private final BaseSafeManageMaterialService baseSafeManageMaterialService;
    private final BaseParkSafeManagerService baseParkSafeManagerService;

    @XxlJob("baseSafeExpireServiceExpireJobHandler")
    public void baseSafeExpireServiceExpireJobHandler() {
        List<BaseSafeManageMaterialEntity> baseSafeManageMaterialEntities = baseSafeManageMaterialService.list();
        List<BaseParkSafeManagerEntity> baseParkSafeManagerEntities = baseParkSafeManagerService.list();
        Date now = new Date();
        // 一个月
        int ONE_MONTH = 1;
        for (BaseSafeManageMaterialEntity baseSafeManageMaterialEntity : baseSafeManageMaterialEntities) {
            Date ineffectiveDate = baseSafeManageMaterialEntity.getIneffectiveDate();
            if (DateUtil.betweenMonth(now,ineffectiveDate,true) <= ONE_MONTH){
                // 一个月后过期
                // todo 发送通知
            }
        }
        for (BaseParkSafeManagerEntity baseParkSafeManagerEntity : baseParkSafeManagerEntities) {
            Date ineffectiveDate = baseParkSafeManagerEntity.getIneffectiveDate();
            if (DateUtil.betweenMonth(now,ineffectiveDate,true) <= ONE_MONTH){
                // 一个月后过期
                // todo 发送通知
            }
        }

    }
}
